package main.java.FSMDE.models;

import java.util.List;
import java.util.UUID;

import main.java.ERMDE.infrastructure.Func;
import main.java.ERMDE.infrastructure.IterableExtensions;
import main.java.ERMDE.models.ModelCollection;


public class TransitionCollection extends ModelCollection<Transition> {

	public TransitionCollection() {
		super();
	}

	public boolean add(Transition transition) {
		if (this.get(transition.getName()) == null) {
			this.items.add(transition);
		}
		return false;
	}

	public Transition get(UUID id) {
		return IterableExtensions.firstOrDefault(this.items,
				new Func<Transition, String, Boolean>() {
					@Override
					public Boolean execute(Transition item, String id) {
						return item.getId().toString().equals(id);
					}
				}, id.toString());
	}

	@Override
	protected Transition createItemInstance(String itemName) {
		return FactoryTransition.createControlTransition(itemName);
	}

	public void remove(Transition transition) {
		this.items.remove(transition);
	}

	public List<Transition> getTransitions() {
		return this.items;
	}

}
